<template>
  <div class="app-container">
    <el-form :model="queryParams"   @submit.native.prevent ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺地址" prop="url">
        <el-input
          v-model="queryParams.url"
          placeholder="输入店铺地址 例如 https://officialselecthome.en.alibaba.com"
          value="shelf"
          clearable
          size="small"
          style="width: 400px"
          aria-placeholder="https://officialselecthome.en.alibaba.com"
          @keyup.enter.native="handleQuery"
        />
        
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
      <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['alibaba:showcase:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
     
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

    <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column label="主图" align="center" prop="imageUrls.x120">
         <template   slot-scope="scope">            
                <el-link  title="点击访问产品"  :href="'https://www.alibaba.com/product-detail/aa_'+scope.row.id+'.html'" target="_blank" class="buttonText"  type="primary" :underline="false"><img :src="scope.row.imageUrls.x120"  /></el-link>
       </template>         
      </el-table-column>
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="标题" align="center"   prop="subject"/>
      <el-table-column label="MOQ" align="center" prop="moq" />
      <el-table-column label="价格" align="center" prop="originalPrice" />
      <el-table-column label="操作" align="center" >
        <template   slot-scope="{row}">            
           <el-link :href="'https://www.alibaba.com/product-detail/aa_'+row.id+'.html'" target="_blank" class="buttonText"  type="primary" :underline="false">访问产品</el-link>
       </template>  
      </el-table-column>
    </el-table>

     <pagination
      v-show="total>0"
      :total="total"
      :page-sizes="[16]"
      :page.sync="queryParams.pageNum"
      @pagination="getList"
    />

 

   
  </div>
</template>

<script>
import { getlist } from "@/api/alibaba/th";

export default {
  name: "Th",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      configList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      typeOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        url: ""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        remark: [
          { required: true, message: "参数名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
},
  methods: {
    getList() {
      this.loading = true;
      getlist(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.configList = response.data;
          this.total = response.total;
          this.loading = false;
        }
      );
    }, 
    imageUrls(row, column) {
        var imgsrc= "https:"+row.imageUrls.x120;
        console.log(imgsrc);
        return '<img src="'+imgsrc+'" referrerpolicy="no-referrer" />';
    },
    promotionTag(row, column) {



    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      
      if(this.queryParams.url.indexOf("en.alibaba.com")==-1){
         this.msgError("店铺地址错误");
        return;
      }
      this.msgSuccess("稍待片刻,查询中");
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.configId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有产品信息?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportConfig(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>